'''
@project:test01
@auther:skj
@file:request_define.py
@date:2022/11/18 15:54
@desc:
'''
import requests
import re
class RequestsDefine():
    def __init__(self):
        self.session=requests.session()
    def create_request(self,req_type,req_url,params=None,data_type=None,data=None,headers=None):
        req_type=req_type.upper()
        res=None
        if req_type=='GET':
            res=self.session.get(url=req_url,params=params,headers=headers)
        elif req_type=='POST':
            if data_type=='json':
               res=self.session.post(url=req_url,params=params,json=data,headers=headers)
            else:
               res=self.session.post(url=req_url,params=params,data=data,headers=headers)
        return res

   #封装正则表达式的提取
    def patter_find(self,pattern,res):  #pattern：第一个参数是正则表达式  res：响应正文
        p = re.compile(pattern)
        result = re.findall(p, res.text)[0]
        return result


